package com.afdor.rws.core.strategy.impl;


import com.afdor.rws.annotation.extension.Extension;
import com.afdor.rws.core.strategy.IdGeneratorStrategy;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * UUID生成器
 *
 * @author 悭梵
 * @date Created in 2018-08-03 18:57
 */
@Extension(value = "uuid", order = Extension.NORMAL_ORDER - 100, interfaceClass = IdGeneratorStrategy.class)
public class UUIDGeneratorStrategyImpl implements IdGeneratorStrategy<String> {

    @Override
    public String generate() {
        return StringUtils.replace(UUID.randomUUID().toString().toLowerCase(), "-", "");
    }

    @Override
    public List<String> generate(int size) {
        List<String> idList = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            idList.add(generate());
        }
        return idList;
    }
}
